package com.factory.test.adapter;

import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.factory.test.R;
import com.factory.test.bean.ActivityItem;

import java.util.List;

public class ActivityItemAdapter extends BaseQuickAdapter<ActivityItem, BaseViewHolder> {

    public ActivityItemAdapter(List<ActivityItem> data) {
        super(R.layout.item_test_activity, data);
    }

    private boolean showAll;

    public void setNewList(List<ActivityItem> list, int stopIndex, boolean showAll){
        this.showAll = showAll;
        if(showAll){
            super.setList(list);
        }else{
            super.setList(list.subList(0, stopIndex));
        }
    }



    @Override
    protected void convert(BaseViewHolder baseViewHolder, ActivityItem activityItem) {
        baseViewHolder.setText(R.id.index, String.valueOf(baseViewHolder.getAdapterPosition() + 1))
                .setText(R.id.name, activityItem.getMenuMenu());

        View view = baseViewHolder.getView(R.id.layout);
        switch (activityItem.getTestResult()) {
            case 0: {
                view.setBackgroundResource(R.drawable.button_blue_selector);
                break;
            }
            case 1: {
                view.setBackgroundResource(R.drawable.button_green_selector);
                break;
            }
            case 2: {
                view.setBackgroundResource(R.drawable.button_red_selector);
                break;
            }
            case 3: {
                view.setBackgroundResource(R.drawable.button_gray_selector);
                break;
            }
        }
    }
}
